"""AdminConfigSeedTableSeeder Seeder."""

from masoniteorm.seeds import Seeder
from app.models.AdminConfig import AdminConfig


class AdminConfigTableSeeder(Seeder):
    def run(self):
        """Run the database seeds."""
        print("清空 admin_configs 数据")
        print("写入 admin_configs 数据")
        AdminConfig.truncate()

        index   = {'title': 0, 'content': 1, 'remark': 2}
        configs = [
            ['website', 'my-admin', '网站名称'],
            ['bei_an', '-', '备案号'],
            ['copyright', 'my-admin', '版权信息'],
            ['watermark_switch', '0', '版权水印'],
        ]

        for config in configs:
            admin_config = AdminConfig.where('title', config[index['title']]).first()
            if admin_config is not None:
                print("{0}: {1} 已存在".format(config[index['title']], config[index['remark']]))
                continue

            print("{0}: {1} 写入成功".format(config[index['title']], config[index['remark']]))
            AdminConfig.generate_log(config[index['title']], config[index['content']], config[index['remark']])
